package com.ld.security.server.user.modules.rec.service.impl;


import cn.hutool.core.date.DateUtil;
import com.ld.security.common.mybatis.base.service.*;
import com.ld.security.server.user.modules.rec.constant.RecCardConstant;
import com.ld.security.server.user.modules.rec.entity.RecItemEntity;
import com.ld.security.server.user.modules.rec.mapping.RecCardMapping;
import com.ld.security.server.user.modules.rec.po.CardClickPo;
import com.ld.security.server.user.modules.rec.service.IRecCardService;

import com.ld.security.server.user.modules.rec.entity.RecCardEntity;

import com.ld.security.server.user.modules.rec.service.IRecCardService;

import com.ld.security.server.user.modules.rec.vo.RecCardVo;
import com.ld.security.server.user.modules.rec.vo.RunUserRecommendVo;
import com.ld.security.server.user.modules.ups.entity.UpsKeywordEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class RecCardServiceImpl  extends ISuperServiceImpl<RecCardEntity>
implements
        IRecCardService {


        @Autowired
        RecCardMapping cardMapping;

        private int offDay = -30;

        @Override
        public void cardClick(CardClickPo po) {
                RecCardEntity cardEntity =  this.newInstance();
                cardEntity.setId(po.getId());
                cardEntity.setStatus(po.getStatus());
                cardMapping.updateById(cardEntity);
        }



        @Override
        public void runUserRecommend(List<String> updsIds) {

                RunUserRecommendVo vo = new RunUserRecommendVo();

                Date end =  new Date();
                Date start =   DateUtil.offsetDay(end,offDay);
                vo.setTimeScope(Arrays.asList(start,end));
                vo.setUpsUserIds(updsIds);
                this.proxyQuery(vo);

                Map<String,List<RecCardEntity>> recMap  =  vo.getRecMap()  ;
                int i = 0;
                for (List<RecCardEntity> recCardEntities : recMap.values()) {

                        this.saveBatch(recCardEntities);
                        i++;
                }
        }


        @Override
        public RecCardVo getCard(String upsUserId) {
                RecCardVo vo = new RecCardVo();
                vo.setUpsUserId(upsUserId);
                this.proxyQuery(vo);
                return vo;

        }
}
